<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">方案名称</div>
                <el-input v-model="search.keywords" placeholder="请输入方案名称" clearable @change="upsearch"></el-input>
                <div class="search-input">保养人员</div>
                <el-input v-model="search.other" placeholder="请输入保养人员" clearable @change="upsearch"></el-input>
                <el-date-picker v-model="time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" :size="size" />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-header>
            <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'mainPlan.add'">新增保养方案</el-button>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border>
                <el-table-column type="selection"  align="center" width="50"></el-table-column>
                <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                <!-- <el-table-column label="设备编号" prop="device_code" align="center"></el-table-column>
                <el-table-column label="设备名称" prop="device_title" align="center"></el-table-column>
                <el-table-column label="设备类别" prop="class_title" align="center"></el-table-column> -->
                <el-table-column label="方案编号" prop="code" align="center"></el-table-column>
                <el-table-column label="方案名称" prop="title" align="center"></el-table-column>
                <el-table-column label="保养人员" prop="other_name" align="center"></el-table-column>
                <el-table-column label="计划名称" prop="plan_title" align="center"></el-table-column>
                <el-table-column label="开始时间" prop="start_time" align="center"></el-table-column>
                <el-table-column label="结束时间" prop="end_time" align="center"></el-table-column>
                <el-table-column label="备注" prop="remark" align="center">
<!--                    <template #default="{row}">-->
<!--                        <el-popover placement="top-start" :width="200" trigger="hover" :content="row.remark">-->
<!--                            <template #reference>-->
<!--                                <el-button style="padding: 5px 0;" text class="m-2" v-if="row.remark">{{row.remark.substring(0, 8)}}</el-button>-->
<!--                            </template>-->
<!--                        </el-popover>-->
<!--                    </template>-->
                </el-table-column>
                <el-table-column label="操作" align="center" width="180">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'mainPlan.eidt'">修改</el-button>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                                <template #reference>
                                    <el-button text type="danger" size="small" v-auth="'mainPlan.delete'">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></save-dialog>
</template>

<script>
import saveDialog from './save'
export default {
	name: 'user',
	components: {
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			groupFilterText: '',
			group: [],
			apiObj: this.$API.device.Project.lists,
			selection: [],
			search:{
                keywords:null,
                device_keywords:null,
                start_time:null,
                end_time:null,
            },
            time:""
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
	},
	methods: {
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
        table_detail(row){
            this.$router.push({
			path: '/device/list/detail',
            query:{
                id:row.id
            }
		})
        },
		//编辑
		table_edit(row) {
            console.log('row :>> ', row);
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
        goLocation(){
            this.$router.push({
                path: 'storeroomLocation',
            })
        },
		//删除
		async table_del(row, index) {
			var reqData = { id: row.id }
			var res = await this.$API.device.Project.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
                this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//搜索
		upsearch() {
            if(this.time!=null){
                this.search.start_time = this.time[0]
                this.search.end_time = this.time[1]
            }else{
                this.search.start_time = ""
                this.search.end_time = ""
            }
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
            this.printArr = ''
		},
        selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
.shopInfo{
    display: flex;
    align-items: center;
}
.img{
    width: 100px;
    height: 100px;
    margin-right: 5px;
}
</style>
